/**
 * Audit-Frontend-Framework(AFF) Demo Server
 */

const express = require('express');
const path = require('path')
const app = express()
const serverPort = require('./config').port;

let resourceRouter = function (res_url, res_path) {
    app.use(res_url, express.static(res_path));
};

// static resource mappings
resourceRouter('/webixasserts', './third/');
resourceRouter('/asserts', './source/');
resourceRouter('/auditasserts', './dist/v-1.0.0/');

// controller
app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'index.html'));
});

let demo_data = [{
        id: 1,
        value: "First",
        name: "Alex",
        last: "Russel",
        address: "Holmes st. 18"
    },
    {
        id: 2,
        value: "Second",
        name: "Denis",
        last: "Brown",
        address: "Greenleaf st. 7"
    },
    {
        id: 3,
        value: "Third",
        name: "James",
        last: "Sullivan",
        address: "Boswell st. 34"
    }
];

// get data results
app.get('/data', (req, res) => {
    res.json(demo_data);
});


// startup server
app.listen(serverPort, () => console.log(`AFF Demo Server listening on port ${serverPort}!`));